<!-- 修改资料页面 -->
<template>
	<view class="modify-data-box">
		<view class="data-item-box" @click="updatePhoneClick">
			<text>手机号码</text>
			<text>{{ (accountData.mobile || '待完善') | setPhone }}</text>
			<u-icon class="icon" name="arrow-right" color="#CCCCCC"></u-icon>
		</view>
		<view class="data-item-box" @click="updateAlipayClick">
			<text>支付宝账号</text>
			<text>{{ accountData.withdraw_info.zfb.account || '待完善' }}</text>
			<u-icon class="icon" name="arrow-right" color="#CCCCCC"></u-icon>
		</view>
		<view class="data-item-box" @click="updateBankAccountClick(1)">
			<text>银行账号</text>
			<text>{{ accountData.withdraw_info.bank.card || '待完善' }}</text>
			<u-icon class="icon" name="arrow-right" color="#CCCCCC"></u-icon>
		</view>
		<view class="data-item-box" @click="updateBankAccountClick(2)">
			<text>银行对公账号</text>
			<text>{{ accountData.withdraw_info.pub_bank.card || '待完善' }}</text>
			<u-icon class="icon" name="arrow-right" color="#CCCCCC"></u-icon>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			accountData: {},
		};
	},
	onShow() {
		this.getData()
	},
	filters: {
		// 定义将用户手机号中间四位使用 * 号代替的过滤器
		setPhone(number) {
			let reg = /^(\d{3})\d{4}(\d{4})$/;
			return number.replace(reg, '$1****$2');
		}
	},
	methods: {
		async getData() {
			const res = await this.$u.api.getProfileDatas()
			if(!res) return
			this.accountData = res
		},
		// 更新手机号区域的点击事件
		updatePhoneClick() {
			this.$u.route('/myPackageA/pages/views/update-phone?phone=' + this.accountData.mobile)	// 跳转到修改手机号码 页面
		},
		// 更新支付宝账号区域的点击事件
		updateAlipayClick() {
			// 跳转到支付宝账号的修改页面
			this.$u.route({
				url: '/myPackageA/pages/views/update-alipay',
				params: this.accountData.withdraw_info.zfb
			});
		},
		// 更新银行卡账号和银行卡对公账号区域的点击事件（如果点击的是银行卡账号则 id 为 1，对公银行卡账号则 id 为 2
		updateBankAccountClick(id) {
			// 判断要携带的参数时银行账号数据还是银行对公账号数据
			if(id === 1) {		// 点击的是 银行账号
				this.$u.route({
					url: `/myPackageA/pages/views/update-bankaccount?id=1`,
					params: this.accountData.withdraw_info.bank
				});
			} else {			// 点击的是 银行对公账号
				this.$u.route({
					url: `/myPackageA/pages/views/update-bankaccount?id=2`,
					params: this.accountData.withdraw_info.pub_bank
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.modify-data-box {
	min-height: 100vh;
	background-color: #f4f6fa;
	padding-top: 20rpx;
	.data-item-box {
		height: 100rpx;
		background-color: white;
		border-bottom: 1rpx solid #e7eaf0;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #141418;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 75rpx 0 25rpx;
		position: relative;
		.icon {
			position: absolute;
			top: 50%;
			right: 25rpx;
			transform: translateY(-50%);
		}
		
	}
}
</style>
